import axios from 'axios';
// import store from '@/store'

const service = axios.create({
	baseURL: process.env.BASE_API, // api的base_url
	timeout: 5000 // request timeout
});

// request interceptor
service.interceptors.request.use(
	config => {
		// Do something before request is sent
		//if (store.getters.token) {
		//	// 让每个请求携带token-- ['X-Token']为自定义key 请根据实际情况自行修改
		//	config.headers['X-Token'] = 'shkludgfjhfsd' //todo 后面再改
		//}
		return config
	},
	error => {
		// Do something with request error
		console.log(error);// for debug
		Promise.reject(error)
	}
);

// respone interceptor
service.interceptors.response.use(
	response => {
		const res = response.data;
		if (res.success != true) {
			console.log("error:" + res.message);
			return Promise.reject('error')
		} else {
			return response.data
		}
	},
	error => {
		console.log('err' + error); // for debug
		return Promise.reject(error)
	}
);

export default service;


